//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    update: '',
    basic:{},
    today:{},
    tomorrow:{},
    afterTomor:{},
   
  },
  onShow: function () {
    this.getLocation();
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  getLocation:function(){
    var that = this;
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        //console.log(res)
        var latitude = res.latitude
        var longitude = res.longitude
        that.getWeatherInfo(latitude, longitude);
      }
    })
  },
  getWeatherInfo: function (latitude, longitude){
    var _this = this;
    var key = '44eeaa2957e04570baf95454dd689e58';
  
    var url = 'https://devapi.qweather.com/v7/weather/now?key='+key+'&location=' + longitude + ',' + latitude;
   // console.log(url)
    wx.request({
      
      url: url, 
      data: {},
      method: 'GET',
      success: function (res) {
          console.log(res)
        var daily_forecast_today = res.data.now.text;//今天预报
      
        var temp= res.data.now.temp;//温度
        var wind = res.data.now.windDir;//风向
        _this.setData({
          wind:wind,
          temp:temp,
          today: daily_forecast_today,
          
   
        });
      }
    })
  }
})

